package com.web.estate.interceptor;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.web.estate.common.UrlBroker;

public class LoginInterceptor extends AbstractHandlerInterceptorAdapter {

	@Resource(name = "loginFilterPaths")
	private List<String> filterPaths;

	@Override
	public List<String> getFilterPaths() {
		return this.filterPaths;
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		UrlBroker urlBroker = new UrlBroker("login");
		urlBroker.addQueryData("goto", getGotoURL(request));
		if (!match(request) && !isLogin(request)) {
			response.sendRedirect(urlBroker.fork());
			return false;
		}
		return true;
	}
}
